
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% The impact of divorce laws on the equilibrium in the marriage market.
% Ana Reynoso
% April 2024
%
% This file estimates the change in the correlation coefficient of spousal 
% education due to the introduction of unilateral divorce and produces the 
% values in the "Data" column in Table A5. 
%  
% Data: PSID 1968-1992
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
*/

*%------------------------ Replication Path -----------------------------------%

clear all

*%--- Indicate location of Replication folder:
*global replication_location "C:\update_with_your_path"

qui{

*%------------------------ Preliminaries --------------------------------------%
	
cd "$replication_location\Validation\Impact_PAM"

u "$replication_location\Data\Inputs\households_psid.dta", clear

*--- Newlyweds
replace year_firstmarriage=s_year_firstmarriage if (year_firstmarriage==9998 | year_firstmarriage==9999) & nbr_marriages==1
replace year_firstmarriage=. if year_firstmarriage==9998 | year_firstmarriage==9999
gen dist= year-year_firstmarriage 
gen newlywed2= (dist==0 | dist==1| dist==2) 
*--- Education types
gen wifesed=.
replace wifesed=1 if weduc<=5 & weduc!=.
replace wifesed=2 if weduc==6
replace wifesed=3 if weduc==7 | weduc==8
gen headsed=.
replace headsed=1 if heduc<=5 & heduc!=.
replace headsed=2 if heduc==6
replace headsed=3 if heduc==7 | heduc==8
*--- State and year dummies
tab state, gen(st_)
tab year, gen(yr_)
forvalues i=1(1)51{ 
gen lineartrend_`i'=year*st_`i'
}
*--- Years since ud
gen years_since_ud = year - ud_year
gen ever_ud=unilateral
replace ever_ud = 1 if ud_year!=.
*--- Consider newlyweds only
keep if s_nbr_marriages==1 & newlywed2==1
*--- Correlation in spousal educ by state and year 
gen correlation = .
forvalues i=1(1)51{
forvalues k=1967(1)1992{
qui capture corr(wifesed  headsed) if state==`i' & year==`k' 
replace correlation = r(rho) if state==`i' & year==`k' 
}
}
*--- Dummies for years since UD
gen bin_ysud=.
replace bin_ysud=1 if (years_since_ud==0|years_since_ud==1 |years_since_ud==2)
replace bin_ysud=2 if (years_since_ud==3 |years_since_ud==4)
replace bin_ysud=3 if (years_since_ud==5 |years_since_ud==6)
replace bin_ysud=4 if (years_since_ud==7 |years_since_ud==8)
replace bin_ysud=5 if (years_since_ud==9 |years_since_ud==10)
replace bin_ysud=6 if years_since_ud>10 & years_since_ud!=.
replace bin_ysud=7 if (years_since_ud==-1 |years_since_ud==-2)
replace bin_ysud=8 if (years_since_ud==-3 |years_since_ud==-4)
replace bin_ysud=9 if (years_since_ud==-5 |years_since_ud==-6)
replace bin_ysud=10 if (years_since_ud==-7 |years_since_ud==-8)
replace bin_ysud=11 if (years_since_ud==-9 |years_since_ud==-10)
replace bin_ysud=12 if years_since_ud<-10 & years_since_ud!=.
replace bin_ysud=13 if ever_ud==0 
replace bin_ysud=. if unilateral==.
tab bin_ysud, gen(binud_)
*--- Marriage markets
gen USCBregion=.
replace USCBregion = 1 if state==44 | state==29 | state==31 | state==37 | state==6 | state==18 | state==20 | state==28 | state==38
replace USCBregion = 2 if state==12 | state==34 | state==24 | state==40 | state==43 | state==13 | state==21 | state==48 | state==14 | state==15|state==22 |state==26 | state==33 | state==2 | state==5 |state==11 | state==30 | state==25 | state==27 | state==49 | state==50 | state==4 | state==51 | state==36 | state==46
replace USCBregion = 3 if state==8 | state==19 | state==32 | state==39 | state==45 | state==47 | state==7 | state==9 | state==10 
replace USCBregion = 4 if state==23 | state==41 | state==3 | state==17 |state==1 | state==16 | state==35 | state==42

*%------------------------ Results --------------------------------------------%

// All Markets
reg correlation binud_1-binud_12 i.state i.year, cluster(state)
qui capture corr(wifesed  headsed) if binud_13==1
gen row_1= _b[binud_1]/r(rho)*100
// Northeast
reg correlation binud_1-binud_12 i.state i.year if USCBregion ==1 , cluster(state)
qui capture corr(wifesed  headsed) if binud_13==1 & USCBregion ==1
gen row_2= _b[binud_1]/r(rho)*100
// Midwest and West
reg correlation binud_1-binud_12 i.state i.year if USCBregion ==2, cluster(state)
qui capture corr(wifesed  headsed) if binud_13==1 & USCBregion ==2
gen row_3= _b[binud_1]/r(rho)*100
// South Atlantic
reg correlation binud_1-binud_12 i.state i.year if USCBregion ==3, cluster(state)
qui capture corr(wifesed  headsed) if binud_13==1 & USCBregion ==3
gen row_4= _b[binud_1]/r(rho)*100
// South Central
reg correlation binud_1-binud_12 i.state i.year if USCBregion ==4, cluster(state)
qui capture corr(wifesed  headsed) if binud_13==1 & USCBregion ==4
gen row_5= _b[binud_1]/r(rho)*100

keep row_1-row_5
duplicates drop

cd "$replication_location\Validation\Impact_PAM\Inputs"

export delimited Table_A5_Data
}


